Completed
Push — master ( 552101...beada9 )
by greg
03:14
created

metas.js ➔ ... ➔ ???   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 16
dl 0
loc 18
rs 8.8571
nop 1
1
import {
2
  cmsData
3
  ,config
4
} from '../../'
5
6
export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') {
7
  let meta = config.meta.name
8
9
  var currentDate = (date != null && date !== '') ? date : new Date()
10
  var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + cmsData.revision.removeStatusAndDateFromFileName(currentDate.toISOString())) + ''
11
12
  if(json[meta].date == null) {
13
    json[meta].date = currentDate
14
  }
15
  json[meta].latest = {
16
    date: currentDate,
17
    abeUrl: abeUrl
18
  }
19
  json[meta].status = realType === 'reject' ? 'draft' : realType
20
  if(json[meta][type] == null) {
21
    json[meta][type] = JSON.parse(JSON.stringify(obj))
22
    json[meta][type].date = currentDate
23
    json[meta][type].abeUrl = abeUrl
24
  }
25
  json[meta][type].latest = JSON.parse(JSON.stringify(obj))
26
  json[meta][type].latest.date = currentDate
27
  json[meta][type].latest.abeUrl = abeUrl
28
}
29